package org.compiere.process;

import java.math.BigDecimal;
import org.compiere.model.Mhrmcheckoffline;
import org.compiere.model.Mhrmtax;
import org.compiere.util.Env;
import org.compiere.util.Msg;

public class GenerateCheckoffLine extends SvrProcess {

	double SUM = .0;
	double rate = .0;
	BigDecimal amount = null;
	
	private Mhrmcheckoffline chkoffline = null;
				
	@Override
	protected void prepare() {
		chkoffline = new Mhrmcheckoffline(getCtx(), getRecord_ID(), null);		
	}

	@Override
	protected String doIt() throws Exception {
			
		// get profit 
		amount = Mhrmtax.getTotal(chkoffline.getC_BPartner_ID(), chkoffline.getDateFrom());
		if (amount == null){
			SUM = chkoffline.gethrm_amountsalary().doubleValue();
		}else{
			SUM = amount.doubleValue();	
		}
		
		if (chkoffline.gethrm_percent() != 0){
			SUM = SUM * chkoffline.gethrm_percent() * 0.01; 
		}else if (chkoffline.gethrm_amount() != null && chkoffline.gethrm_percent() == 0){
			SUM =  chkoffline.gethrm_amount().doubleValue();
		}else{
			SUM = .0;				
		}
				
		SUM = SUM + chkoffline.getCommission().doubleValue() + chkoffline.gethrm_postage().doubleValue(); 
		chkoffline.sethrm_total(new BigDecimal(SUM));		
		chkoffline.saveEx();
					
		return Msg.translate(Env.getCtx(), "Success");
		
	}

}
